using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using HeThongDAO;
using NUnit.Framework;
using System.Data;

namespace _041346_1041351_1041352_UnitTest
{
    [TestFixture]
    public class TestBaoCaoCongNo
    {
        [Test]
        public void TestBaoCaoCongNo1()
        {
            double nokhachhang = 30000;
            KhachHangDTO kh = new KhachHangDTO();
            kh.IMaKhachHang = 2;
            DataTable dttongmua = KhachHangDAO.LayTongMuaTuThang(kh, 5, 2011);
            DataTable dttongtra = KhachHangDAO.LayTongTraTuThang(kh, 5, 2011);
            double nodau = 0;
            double tongmua_tuthang = 0;
            double tongtra_tuthang = 0;
            try
            {
                DataRow drtongmua_tuthang = dttongmua.Rows[0];
                tongmua_tuthang = double.Parse(drtongmua_tuthang["TongMua"].ToString());
            }
            catch
            {

            }
            try
            {
                DataRow drtongtra_tuthang = dttongtra.Rows[0];
                tongtra_tuthang = double.Parse(drtongtra_tuthang["TongTra"].ToString());
            }
            catch
            {

            }
            nodau = nokhachhang + tongtra_tuthang - tongmua_tuthang;

            dttongmua = KhachHangDAO.LayTongMuaTrongThang(kh, 5, 2011);
            dttongtra = KhachHangDAO.LayTongTraTrongThang(kh, 5, 2011);
            double tongmua_trongthang = 0;
            double tongtra_trongthang = 0;
            try
            {
                DataRow drtongmua_trongthang = dttongmua.Rows[0];
                tongmua_trongthang = double.Parse(drtongmua_trongthang["TongMua"].ToString());
            }
            catch
            {

            }
            try
            {
                DataRow drtongtra_trongthang = dttongtra.Rows[0];
                tongtra_trongthang = double.Parse(drtongtra_trongthang["TongTra"].ToString());
            }
            catch
            {

            }
            double phatsinh = tongmua_trongthang - tongtra_trongthang;
            double nocuoi = nodau + (tongmua_trongthang - tongtra_trongthang);

            //tao du lieu test
            double testnodau = 42000;
            double testphatsinh = -12000;
            double testnocuoi = 30000;

            Assert.AreEqual(testnodau, nodau);
            Assert.AreEqual(testnocuoi, nocuoi);
            Assert.AreEqual(testphatsinh, phatsinh);
        }
        [Test]
        public void TestBaoCaoCongNo2()
        {
            double nokhachhang = 30000;
            KhachHangDTO kh = new KhachHangDTO();
            kh.IMaKhachHang = 2;
            DataTable dttongmua = KhachHangDAO.LayTongMuaTuThang(kh, 5, 2011);
            DataTable dttongtra = KhachHangDAO.LayTongTraTuThang(kh, 5, 2011);
            double nodau = 0;
            double tongmua_tuthang = 0;
            double tongtra_tuthang = 0;
            try
            {
                DataRow drtongmua_tuthang = dttongmua.Rows[0];
                tongmua_tuthang = double.Parse(drtongmua_tuthang["TongMua"].ToString());
            }
            catch
            {

            }
            try
            {
                DataRow drtongtra_tuthang = dttongtra.Rows[0];
                tongtra_tuthang = double.Parse(drtongtra_tuthang["TongTra"].ToString());
            }
            catch
            {

            }
            nodau = nokhachhang + tongtra_tuthang - tongmua_tuthang;

            dttongmua = KhachHangDAO.LayTongMuaTrongThang(kh, 5, 2011);
            dttongtra = KhachHangDAO.LayTongTraTrongThang(kh, 5, 2011);
            double tongmua_trongthang = 0;
            double tongtra_trongthang = 0;
            try
            {
                DataRow drtongmua_trongthang = dttongmua.Rows[0];
                tongmua_trongthang = double.Parse(drtongmua_trongthang["TongMua"].ToString());
            }
            catch
            {

            }
            try
            {
                DataRow drtongtra_trongthang = dttongtra.Rows[0];
                tongtra_trongthang = double.Parse(drtongtra_trongthang["TongTra"].ToString());
            }
            catch
            {

            }
            double phatsinh = tongmua_trongthang - tongtra_trongthang;
            double nocuoi = nodau + (tongmua_trongthang - tongtra_trongthang);

            //tao du lieu test
            double testnodau = 52000;
            double testphatsinh = 12000;
            double testnocuoi = 10000;

            Assert.AreEqual(testnodau, nodau);
            Assert.AreEqual(testnocuoi, nocuoi);
            Assert.AreEqual(testphatsinh, phatsinh);

        }
    }
}
